<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="node.js初学习"><meta name="keywords" content="node"><meta name="author" content="晟松"><meta name="copyright" content="晟松"><title>node.js初学习 | 晟松</title><link rel="shortcut icon" href="/logo.png"><link rel="stylesheet" href="/css/index.css?version=1.9.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.9.0"><meta name="format-detection" content="telephone=no"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://hm.baidu.com"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?c34d81d53341febe06a155941e2df16d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();</script><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  hexoVersion: '5.4.0'
} </script><meta name="generator" content="Hexo 5.4.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar" data-display="true"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%9C%AC%E5%9C%B0%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">本地安装</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%85%A8%E5%B1%80%E5%AE%89%E8%A3%85"><span class="toc-number">2.</span> <span class="toc-text">全局安装</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%BC%82%E6%AD%A5%E5%92%8C%E5%90%8C%E6%AD%A5"><span class="toc-number">3.</span> <span class="toc-text">异步和同步</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%89%93%E5%BC%80%E6%96%87%E4%BB%B6%E7%AD%89"><span class="toc-number">4.</span> <span class="toc-text">打开文件等</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%86%99%E5%85%A5%E6%96%87%E4%BB%B6"><span class="toc-number">5.</span> <span class="toc-text">写入文件</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E8%AF%BB%E5%8F%96%E6%96%87%E4%BB%B6"><span class="toc-number">6.</span> <span class="toc-text">读取文件</span></a></li></ol></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="/img/avatar.png"></div><div class="author-info__name text-center">晟松</div><div class="author-info__description text-center">晟松的博客</div><div class="follow-button"><a target="_blank" rel="noopener" href="https://gitee.com/cheng_song">Gitee</a></div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">52</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">45</span></a></div></div></div><div id="content-outer"><div id="top-container" style="background-image: url(/img/blog-bg.jpg)"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">晟松</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus">   <a class="site-page" href="/">Home</a><a class="site-page" href="/archives">Archives</a><a class="site-page" href="/tags">Tags</a><a class="site-page" href="/categories">Categories</a></span><span class="pull-right"><a class="site-page social-icon search"><i class="fa fa-search"></i><span> 搜索</span></a></span></div><div id="post-info"><div id="post-title">node.js初学习</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2020-08-04</time><div class="post-meta-wordcount"><span>字数总计: </span><span class="word-count">2.3k</span><span class="post-meta__separator">|</span><span>阅读时长: 8 分钟</span></div></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><p>多个地方的node学习，<a target="_blank" rel="noopener" href="https://www.runoob.com/nodejs/nodejs-http-server.html">包括菜鸟教程</a>，B站，<a target="_blank" rel="noopener" href="http://www.cpengx.cn/p/386.html">老陈这些</a>。</p>
<p>1.介绍</p>
<p>主要用于编写服务端程序，类似于javaweb里面的jsp这些。</p>
<p><strong>二、Node.js与javaScript</strong></p>
<table>
<thead>
<tr>
<th align="left">javaScript</th>
<th align="left">Node.js</th>
</tr>
</thead>
<tbody><tr>
<td align="left">客户端技术，运行于浏览器中</td>
<td align="left">服务器端技术 ，与php,jsp等是类似的技术</td>
</tr>
<tr>
<td align="left">有多种解释器可以使用，如IE的Chakra,FF的猴子系列，Chrome的V8等等</td>
<td align="left">只能运行于基于V8引擎改进而来的运行时环境</td>
</tr>
<tr>
<td align="left">因为解释器有多种，所以存在代码兼容性问题</td>
<td align="left">只有一种解释器，所以不存在代码兼容性问题</td>
</tr>
<tr>
<td align="left">支持ES对象，自定义对象，BOM&amp;DOM对象</td>
<td align="left">支持ES对象，自定义对象，Node.js扩展对象（大量）</td>
</tr>
<tr>
<td align="left">主要用于网页DOM元素的操作，实现用户交互效果</td>
<td align="left">主要用于实现服务器端运行逻辑，如文件系统操作，数据库访问，其他服务器调用等</td>
</tr>
</tbody></table>
<p>3.Node.js 应用是由哪几部分组成的：</p>
<ol>
<li><p><strong>引入 required 模块：</strong>我们可以使用 <strong>require</strong> 指令来载入 Node.js 模块。当需要导入一个文件，在被导入的文件里需要通过module.exports导出</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> http = <span class="built_in">require</span>(<span class="string">&quot;http&quot;</span>);<span class="comment">//http是内置的模块</span></span><br><span class="line"><span class="keyword">let</span> fs = <span class="built_in">require</span>(<span class="string">&quot;./fs.js&quot;</span>);<span class="comment">//导入一个fs.js文件</span></span><br></pre></td></tr></table></figure></li>
<li><p><strong>创建服务器：</strong>服务器可以监听客户端的请求，类似于 Apache 、Nginx 等 HTTP 服务器。</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line">http.createServer(<span class="function"><span class="keyword">function</span> (<span class="params">request, response</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 发送 HTTP 头部 </span></span><br><span class="line">    <span class="comment">// HTTP 状态值: 200 : OK</span></span><br><span class="line">    <span class="comment">// 内容类型: text/plain</span></span><br><span class="line">    response.writeHead(<span class="number">200</span>, &#123;<span class="string">&#x27;Content-Type&#x27;</span>: <span class="string">&#x27;text/plain&#x27;</span>&#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 发送响应数据 &quot;Hello World&quot;</span></span><br><span class="line">    response.end(<span class="string">&#x27;Hello World\n&#x27;</span>);</span><br><span class="line">&#125;).listen(<span class="number">8888</span>);<span class="comment">//端口号</span></span><br></pre></td></tr></table></figure></li>
<li><p><strong>接收请求与响应请求</strong> 服务器很容易创建，客户端可以使用浏览器或终端发送 HTTP 请求，服务器接收请求后返回响应数据。</p>
</li>
</ol>
<p>4.NPM</p>
<p>是随同NodeJS一起安装的包管理工具，能解决NodeJS代码部署上的很多问题</p>
<p>​    1.使用npm安装模块</p>
<figure class="highlight powershell"><table><tr><td class="code"><pre><span class="line"><span class="variable">$</span> npm install &lt;Module Name&gt;</span><br><span class="line"></span><br><span class="line">var express = require(<span class="string">&#x27;modele name&#x27;</span>);//使用require引用</span><br></pre></td></tr></table></figure>

<figure class="highlight powershell"><table><tr><td class="code"><pre><span class="line">npm install express          <span class="comment"># 本地安装</span></span><br><span class="line">npm install express <span class="literal">-g</span>   <span class="comment"># 全局安装</span></span><br></pre></td></tr></table></figure>

<h6 id="本地安装"><a href="#本地安装" class="headerlink" title="本地安装"></a>本地安装</h6><ul>
<li>\1. 将安装包放在 ./node_modules 下（运行 npm 命令时所在的目录），如果没有 node_modules 目录，会在当前执行 npm 命令的目录下生成 node_modules 目录。</li>
<li>\2. 可以通过 require() 来引入本地安装的包。</li>
</ul>
<h6 id="全局安装"><a href="#全局安装" class="headerlink" title="全局安装"></a>全局安装</h6><ul>
<li>\1. 将安装包放在 /usr/local 下或者你 node 的安装目录。</li>
<li>\2. 可以直接在命令行里使用</li>
</ul>
<p>2.packag.json</p>
<p>package.json 位于模块的目录下，用于定义包的属性。位于 node_modules/modules name/package.json </p>
<p>在里面的最直观的是<strong>dependencies</strong> - 依赖包列表。如果依赖包没有安装，npm 会自动将依赖包安装在 node_module 目录下。</p>
<p>5.回调函数，为了提高并发请求的处理，可不阻塞的执行代码</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> fs = <span class="built_in">require</span>(<span class="string">&quot;fs&quot;</span>);</span><br><span class="line"></span><br><span class="line">fs.readFile(<span class="string">&#x27;input.txt&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">err, data</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (err) <span class="keyword">return</span> <span class="built_in">console</span>.error(err);</span><br><span class="line">    <span class="built_in">console</span>.log(data.toString());</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&quot;程序执行结束!&quot;</span>);</span><br><span class="line"><span class="comment">//结果</span></span><br><span class="line">$ node main.js</span><br><span class="line">程序执行结束!</span><br><span class="line">菜鸟教程官网地址：www.runoob.com</span><br></pre></td></tr></table></figure>

<p>6.EventEmitter</p>
<p>一个对事件的处理函数，类似于之前的sokect</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 引入 events 模块</span></span><br><span class="line"><span class="keyword">var</span> events = <span class="built_in">require</span>(<span class="string">&#x27;events&#x27;</span>);</span><br><span class="line"><span class="comment">// 创建 eventEmitter 对象</span></span><br><span class="line"><span class="keyword">var</span> EventEmitter = <span class="keyword">new</span> events.EventEmitter();</span><br><span class="line"><span class="keyword">var</span> event = <span class="keyword">new</span> EventEmitter(); </span><br><span class="line">event.on(<span class="string">&#x27;name&#x27;</span>,<span class="function"><span class="keyword">function</span>(<span class="params">arg1,arg2</span>)</span>&#123;&#125;);<span class="comment">//监听事件</span></span><br><span class="line">event.emit(<span class="string">&#x27;name&#x27;</span>,<span class="string">&#x27;arg1&#x27;</span>,<span class="string">&#x27;arg2&#x27;</span>);<span class="comment">//触发事件,可带参数</span></span><br></pre></td></tr></table></figure>

<p>7.buffer缓冲区</p>
<p>JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在<strong>处理像TCP流或文件流</strong>时，必须使用到二进制数据。因此在 Node.js中，定义了一个 Buffer 类，该类用来创建一个专门存放二进制数据的缓存区。有自己的特定编码</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 创建一个长度为 10、且用 0 填充的 Buffer。</span></span><br><span class="line"><span class="keyword">const</span> buf = Buffer.alloc(<span class="number">10</span>);、</span><br><span class="line"></span><br><span class="line"><span class="comment">//写入缓冲区,如果 buffer 空间不足， 则只会写入部分字符串</span></span><br><span class="line">len = buf.write(<span class="string">&quot;www.runoob.com&quot;</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">&quot;写入字节数 : &quot;</span>+  len);<span class="comment">// 写入字节数：14</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//从缓冲区读数据</span></span><br><span class="line"><span class="built_in">console</span>.log( buf.toString(<span class="string">&#x27;ascii&#x27;</span>,<span class="number">0</span>,<span class="number">5</span>));   <span class="comment">//使用 &#x27;ascii&#x27; 编码, 并输出: www.r，后面两个参数为起始位置和结束位置</span></span><br><span class="line"><span class="built_in">console</span>.log( buf.toString(<span class="string">&#x27;utf8&#x27;</span>,<span class="number">0</span>,<span class="number">5</span>));    <span class="comment">// 使用 &#x27;utf8&#x27; 编码, 并输出: www.r</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//将buffer转换为json,当字符串化一个 Buffer 实例时，JSON.stringify() 会隐式地调用该 toJSON()。返回json对象</span></span><br><span class="line"><span class="keyword">const</span> json = <span class="built_in">JSON</span>.stringify(buf);</span><br></pre></td></tr></table></figure>

<p>后面还有一些方法，在<a target="_blank" rel="noopener" href="https://www.runoob.com/nodejs/nodejs-buffer.html">菜鸟</a>那里需要的时候看吧。</p>
<p>8.stream</p>
<p>Stream 是一个抽象接口，Node 中有很多对象实现了这个接口。例如，对http 服务器发起请求的request 对象就是一个 Stream，还有stdout（标准输出）</p>
<p>所有的 Stream 对象都是 EventEmitter 的实例。常用的事件有：</p>
<ul>
<li><strong>data</strong> - 当有数据可读时触发。</li>
<li><strong>end</strong> - 没有更多的数据可读时触发。</li>
<li><strong>error</strong> - 在接收和写入过程中发生错误时触发。</li>
<li><strong>finish</strong> - 所有数据已被写入到底层系统时触发。</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://www.runoob.com/nodejs/nodejs-stream.html">具体看菜鸟</a></p>
<p>9.模块化</p>
<p>模块是Node.js 应用程序的基本组成部分，文件和模块是一一对应的。换言之，一个 Node.js 文件就是一个模块，这个文件可能是JavaScript 代码、JSON 或者编译过的C/C++ 扩展。</p>
<p>Node.js 提供了 exports 和 require 两个对象，其中 exports 是模块公开的接口，require 用于从外部获取一个模块的接口，即所获取模块的 exports 对象</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Hello</span>(<span class="params"></span>) </span>&#123; </span><br><span class="line">    <span class="keyword">var</span> name; </span><br><span class="line">    <span class="built_in">this</span>.setName = <span class="function"><span class="keyword">function</span>(<span class="params">thyName</span>) </span>&#123; </span><br><span class="line">        name = thyName; </span><br><span class="line">    &#125;; </span><br><span class="line">    <span class="built_in">this</span>.sayHello = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; </span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&#x27;Hello &#x27;</span> + name); </span><br><span class="line">    &#125;; </span><br><span class="line">&#125;; </span><br><span class="line"><span class="built_in">module</span>.exports = Hello;<span class="comment">//进行导出</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> Hello = <span class="built_in">require</span>(<span class="string">&#x27;./hello&#x27;</span>);<span class="comment">//进行引入 </span></span><br><span class="line">hello = <span class="keyword">new</span> Hello(); </span><br><span class="line">hello.setName(<span class="string">&#x27;BYVoid&#x27;</span>); </span><br><span class="line">hello.sayHello(); </span><br></pre></td></tr></table></figure>

<p>10.函数</p>
<p>一个函数可以作为另一个函数的参数,也可以在传递参数的地方直接定义函数.</p>
<p>11.路由</p>
<p>结合之下vue的路由来看基本没太大的变化，更多的是多了些关于相对底层的原理实现。</p>
<p><strong>setTimeout(cb, ms)</strong> 全局函数在指定的毫秒(ms)数后执行指定函数(cb)。：setTimeout() 只执行一次指定函数。</p>
<p><strong>setInterval(cb, ms)</strong> 全局函数在指定的毫秒(ms)数后执行指定函数(cb)。setInterval() 方法会不停地调用函数，直到 clearInterval() 被调用或窗口被关闭。</p>
<p>12.node常用工具<strong>util</strong> </p>
<p>util 是一个Node.js 核心模块，提供常用函数的集合，用于弥补核心 JavaScript 的功能 过于精简的不足。</p>
<p>使用方法如下：</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> util = <span class="built_in">require</span>(<span class="string">&#x27;util&#x27;</span>);</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://www.runoob.com/nodejs/nodejs-util.html">具体函数看菜鸟</a></p>
<p>13.文件系统</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> fs = <span class="built_in">require</span>(<span class="string">&quot;fs&quot;</span>) <span class="comment">//fileSystem</span></span><br></pre></td></tr></table></figure>

<h6 id="异步和同步"><a href="#异步和同步" class="headerlink" title="异步和同步"></a>异步和同步</h6><p>Node.js 文件系统（fs 模块）模块中的方法均有异步和同步版本，例如读取文件内容的函数有异步的 fs.readFile() 和同步的 fs.readFileSync()。</p>
<p>异步的方法函数最后一个参数为回调函数，回调函数的第一个参数包含了错误信息(error)。建议使用异步方法，比起同步，异步方法性能更高，速度更快，而且没有阻塞。就是可以直接执行读写文件后面的代码指令，而不需要等待文件读写完成。</p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line">fs.readFile(<span class="string">&#x27;input.txt&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">err, data</span>) </span>&#123;<span class="comment">//回调错误函数</span></span><br><span class="line">   <span class="keyword">if</span> (err) &#123;</span><br><span class="line">       <span class="keyword">return</span> <span class="built_in">console</span>.error(err);</span><br><span class="line">   &#125;</span><br><span class="line">   <span class="built_in">console</span>.log(<span class="string">&quot;异步读取: &quot;</span> + data.toString());</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 同步读取，主要看那sync</span></span><br><span class="line"><span class="keyword">var</span> data = fs.readFileSync(<span class="string">&#x27;input.txt&#x27;</span>);</span><br></pre></td></tr></table></figure>

<h6 id="打开文件等"><a href="#打开文件等" class="headerlink" title="打开文件等"></a>打开文件等</h6><figure class="highlight js"><table><tr><td class="code"><pre><span class="line">fs.open(path, flags[, mode], callback) <span class="comment">//flags为文件打开行为</span></span><br><span class="line">fs.stat(path, callback) <span class="comment">//获取文件信息，会将stats类的实例返回给其回调函数。可以通过stats类中的提供方法判断文件的相关属性</span></span><br><span class="line">fs.stat(<span class="string">&#x27;/Users/liuht/code/itbilu/demo/fs.js&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">err, stats</span>) </span>&#123; <span class="comment">//类似如此</span></span><br><span class="line">    <span class="built_in">console</span>.log(stats.isFile());         <span class="comment">//true</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p><a target="_blank" rel="noopener" href="https://www.runoob.com/nodejs/nodejs-fs.html">具体参数参考菜鸟</a></p>
<h6 id="写入文件"><a href="#写入文件" class="headerlink" title="写入文件"></a>写入文件</h6><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">fs.writeFile(file, data[, options], callback)</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>file</strong> - 文件名或文件描述符。</li>
<li><strong>data</strong> - 要写入文件的数据，可以是 String(字符串) 或 Buffer(缓冲) 对象。</li>
<li><strong>options</strong> - 该参数是一个对象，包含 {encoding, mode, flag}。默认编码为 utf8, 模式为 0666 ， flag 为 ‘w’,该方法写入的内容会覆盖旧的文件内容。</li>
<li><strong>callback</strong> - 回调函数，回调函数只包含错误信息参数(err)，在写入失败时返回。</li>
</ul>
<h6 id="读取文件"><a href="#读取文件" class="headerlink" title="读取文件"></a>读取文件</h6><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">fs.read(fd, buffer, offset, length, position, callback);</span><br><span class="line">//示例</span><br><span class="line">var buf = new Buffer.alloc(1024);</span><br><span class="line">fs.read(fd, buf, 0, buf.length, 0, function(err, bytes)&#123;</span><br><span class="line">      if (err)&#123;</span><br><span class="line">         console.log(err);</span><br><span class="line">      &#125;</span><br><span class="line">      console.log(bytes + &quot;  字节被读取&quot;);</span><br><span class="line">      // 仅输出读取的字节</span><br><span class="line">      if(bytes &gt; 0)&#123;</span><br><span class="line">         console.log(buf.slice(0, bytes).toString());</span><br><span class="line">      &#125;</span><br><span class="line">   &#125;);</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>fd</strong> - 通过 fs.open() 方法返回的文件描述符。</li>
<li><strong>buffer</strong> - 数据写入的缓冲区。</li>
<li><strong>offset</strong> - 缓冲区写入的写入偏移量。</li>
<li><strong>length</strong> - 要从文件中读取的字节数。</li>
<li><strong>position</strong> - 文件读取的起始位置，如果 position 的值为 null，则会从当前文件指针的位置读取。</li>
<li><strong>callback</strong> - 回调函数，有三个参数err, bytesRead, buffer，err 为错误信息， bytesRead 表示读取的字节数，buffer 为缓冲区对象。</li>
</ul>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">晟松</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://chengsong.info/2020/08/04/node-js初学习/">https://chengsong.info/2020/08/04/node-js初学习/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://chengsong.info">晟松</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/node/">node</a></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2020/08/22/vue%E9%A1%B9%E7%9B%AEaxios%E5%B0%81%E8%A3%85%E4%B8%8Emock%E4%BD%BF%E7%94%A8/"><i class="fa fa-chevron-left">  </i><span>vue项目axios封装与mock等使用</span></a></div><div class="next-post pull-right"><a href="/2020/07/29/typescript%E5%88%9D%E5%AD%A6%E4%B9%A0/"><span>typescript初学习</span><i class="fa fa-chevron-right"></i></a></div></nav></div></div><footer class="footer-bg" style="background-image: url(/img/blog-bg.jpg)"><div class="layout" id="footer"><div class="copyright">&copy;2020 - 2023 By 晟松</div><div class="framework-info"><span>驱动 - </span><a target="_blank" rel="noopener" href="http://hexo.io"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a target="_blank" rel="noopener" href="https://github.com/Molunerfinn/hexo-theme-melody"><span>Melody</span></a></div><div class="icp"><a target="_blank" rel="noopener" href="http://www.beian.miit.gov.cn/"><span>湘ICP备2020021729号</span></a></div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv"><i class="fa fa-file"></i><span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.9.0"></script><script src="/js/fancybox.js?version=1.9.0"></script><script src="/js/sidebar.js?version=1.9.0"></script><script src="/js/copy.js?version=1.9.0"></script><script src="/js/fireworks.js?version=1.9.0"></script><script src="/js/transition.js?version=1.9.0"></script><script src="/js/scroll.js?version=1.9.0"></script><script src="/js/head.js?version=1.9.0"></script><script src="/js/search/local-search.js"></script><script>if(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
  $('#top-container').addClass('is-mobile')
}</script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html>